package org.summerframework.component.note.config;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 石超
 * @version v1.0.0
 */
@Getter
@Setter
@ConfigurationProperties("note")
public class NoteProperties {
    /**
     * 是否发送测试验证码
     */
    private boolean enableTest = false;
    /**
     * 测试验证码
     */
    private String testCode = "111111";
    /**
     * 设置模板过期时间
     */
    private Map<String, Duration> expireTimes = new HashMap<>();
    /**
     * 默认的过期时间
     */
    private Duration defaultExpireTime = Duration.ofMinutes(30);
    /**
     * 验证发送验证码的条数限制
     */
    @NestedConfigurationProperty
    private CheckSendProperties code = new CheckSendProperties(1, 5, 10, 100);
    /**
     * 验证发送通知的条数限制
     */
    @NestedConfigurationProperty
    private CheckSendProperties inform = new CheckSendProperties(10, 50, 100, 1000);

    public Duration getExpireTime(String templateCode) {
        return expireTimes.getOrDefault(templateCode, defaultExpireTime);
    }

    @Getter
    @Setter
    @NoArgsConstructor
    @AllArgsConstructor
    public static class CheckSendProperties {
        private Integer minute;
        private Integer hour;
        private Integer day;
        private Integer ip;
    }
}
